﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.Reflection;

namespace WindowsGame1
{
    class TilesetReader : ContentTypeReader<Tileset>
    {
        protected override Tileset Read(
        ContentReader input, Tileset existingInstance)
        {
            string textureName = input.ReadString();
            int tileWidth = input.ReadInt32();
            int tileHeight = input.ReadInt32();
            int tileCount = input.ReadInt32();
            List<Rectangle> tiles = new List<Rectangle>();
            for (int i = 0; i < tileCount; i++)
            {
                int xValue = input.ReadInt32();
                int yValue = input.ReadInt32();
                int width = input.ReadInt32();
                int height = input.ReadInt32();
                Rectangle rect = new Rectangle(xValue,
                yValue,
                width,
                height);
                tiles.Add(rect);
            }
            return new Tileset(textureName, tileWidth, tileHeight, tiles);
        }
    }
}
